package com.lvtulife.paas.gtd.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.lvtulife.paas.gtd.entity.GtdIdeal;
import com.lvtulife.paas.gtd.service.GtdIdealServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lvtulife.paas.gtd.mapper.GtdIdealOplogMapper;
import com.lvtulife.paas.gtd.entity.GtdIdealOplog;
import com.lvtulife.paas.gtd.service.GtdIdealOplogServiceI;
import com.lvtulife.common.service.impl.BaseServiceImpl;

import java.util.Date;
import java.util.List;

/**
 * GtdIdealOplog 表数据服务层接口实现类
 */
@Service
public class GtdIdealOplogServiceImpl extends BaseServiceImpl<GtdIdealOplogMapper, GtdIdealOplog> implements GtdIdealOplogServiceI {

    @Override
    public Long saveOplog(Long idealId, String content) {
        verifyParams(idealId, content);

        GtdIdealOplog entity = new GtdIdealOplog();
        entity.setLid(idealId);
        entity.setContent(content);
        entity.setOpDt(new Date());

        int count = baseMapper.insert(entity);
        checkOperation(count);

        return entity.getId();
    }

    @Override
    public void delOplog(Long id) {
        deleteById(id);
    }

    @Override
    public void clearIdealOplog(Long idealId) {
        GtdIdealOplog entity = new GtdIdealOplog();
        entity.setLid(idealId);
        deleteSelective(entity);
    }

    @Override
    public List<GtdIdealOplog> findOplogs(Long idealId) {
        EntityWrapper<GtdIdealOplog> wrapper = new EntityWrapper<>();
        wrapper.where("lid={0}", idealId);
        wrapper.orderBy("opDt", false);
        return selectList(wrapper);
    }

}